// components/review-btn/review-btn.js
import Http from '../../utils/http.js';
const http = new Http();
const app = getApp();

Component({
    /**
     * 组件的属性列表
     */
    properties: {
        type: String,
        infoId: String,
        operatorid: String,
        ftspecialid: String,
    },

    /**
     * 组件的初始数据
     */
    data: {
        btuBottom: 0,
        typeValue: [
            {
                name: '录入了FT测试点',
                type: '01',
                path:
                    '/releasePage/pages/homePageInfo/homePageInfo?review=01&current=0&id=',
            },
            {
                name: '录入了NFC测试点',
                type: '02',
                path:
                    '/releasePage/pages/homePageInfo/homePageInfo?review=01&current=2&id=',
            },
            {
                name: '录入了FT测试路线',
                type: '03',
                path:
                    '/releasePage/pages/homePageInfo/homePageInfo?review=01&current=1&id=',
            },
            {
                name: '录入了NFC测试路线',
                type: '04',
                path:
                    '/releasePage/pages/homePageInfo/homePageInfo?review=01&current=3&id=',
            },
            {
                name: '发布了城市公告',
                type: '06',
                path:
                    '/releasePage/pages/addCitytip/addCitytip?review=01&type=01&id=',
                //type  设置标题
            },
            {
                name: '发起了互动问答',
                type: '08',
                path:
                    '/releasePage/pages/publishQuestion/publishQuestion?review=01&questionId=',
            },
            {
                name: '发布了租车推荐',
                type: '11',
                path:
                    '/releasePage/pages/addFood/addFood?review=01&type=02&cszx=01&id=',
                //type  设置标题
            },
            {
                name: '发布了住宿推荐',
                type: '12',
                path:
                    '/releasePage/pages/addFood/addFood?review=01&type=02&cszx=03&id=',
            },
            {
                name: '发布了出行建议',
                type: '13',
                path:
                    '/releasePage/pages/addFood/addFood?review=01&type=02&cszx=04&id=',
            },
            {
                name: '发布了美食推荐',
                type: '14',
                path:
                    '/releasePage/pages/addFood/addFood?review=01&type=02&cszx=02&id=',
            },
            {
                name: '发布了营业厅信息',
                type: '15',
                path:
                    '/releasePage/pages/addBusinessHall/addBusinessHall?review=01&id=',
            },
            {
                name: '录入基站参数',
                type: '16',
                path: '/releasePage/pages/operatorInfo/operatorInfo?review=01',
            },
            {
                name: '新建了运营商',
                type: '17',
                path:
                    '/releasePage/pages/addOperator/addOperator?review=01&id=',
            },
            {
                name: '新建了套餐建议',
                type: '18',
                path: '/releasePage/pages/addPackage/addPackage?review=01&id=',
            },
        ],
    },

    lifetimes: {
        attached: function () {
            var _that = this;
            wx.getSystemInfo({
                success: function (res) {
                    //model中包含着设备信息
                    var model = res.model;
                    if (model.search('iPhone X') != -1) {
                        _that.setData({
                            btuBottom: 34,
                        });
                    }
                },
            });
        },
    },
    /**
     * 组件的方法列表
     */
    methods: {
        makeGood() {
            let _that = this;
            wx.showModal({
                title: '提示',
                content: '确认要推优这条数据吗？',
                success: function (res) {
                    if (res.confirm) {
                        console.log('推优');
                        _that.getRequest('09');
                    } else {
                        console.log('点击取消回调');
                    }
                },
            });
        },
        makeFinish() {
            let _that = this;
            wx.showModal({
                title: '提示：',
                content: '确认要通过这条数据吗？',
                success: function (res) {
                    if (res.confirm) {
                        console.log('通过');
                        _that.getRequest('00');
                    } else {
                        console.log('点击取消回调');
                    }
                },
            });
        },
        makeDelete() {
            let _that = this;
            if (_that.data.type == '05' || _that.data.type == '10') {
                wx.showModal({
                    title: '提示',
                    content: '确认要删除这条数据吗？',
                    success: function (res) {
                        if (res.confirm) {
                            wx.navigateTo({
                                url: `/releasePage/pages/reviewReason/reviewReason?fromWhere=${
                                    _that.data.type == '05' ? '00' : '01'
                                }&delflg=01&type=${_that.data.type}&id=${
                                    _that.data.infoId
                                }`,
                            });
                        } else {
                            console.log('点击取消回调');
                        }
                    },
                });
            } else {
                wx.showModal({
                    title: '提示：',
                    content: '是否编辑本条数据后再发布？',
                    cancelText: '直接删除',
                    confirmText: '编辑发布',
                    success: function (res) {
                        if (res.confirm) {
                            let url;
                            for (
                                let i = 0;
                                i < _that.data.typeValue.length;
                                i++
                            ) {
                                if (
                                    _that.data.typeValue[i].type ==
                                    _that.data.type
                                ) {
                                    url = _that.data.typeValue[i].path;
                                }
                            }
                            if (_that.data.type == '16') {
                                url =
                                    url +
                                    `&id=${_that.data.ftspecialid}&type=01&netId=${_that.data.infoId}&operid=${_that.data.operatorid}`;
                            } else {
                                url = url + _that.data.infoId;
                            }
                            wx.navigateTo({
                                url: url,
                            });
                        } else {
                            wx.navigateTo({
                                url: `/releasePage/pages/reviewReason/reviewReason?fromWhere=${
                                    _that.data.type == '05' ? '00' : '01'
                                }&delflg=01&type=${_that.data.type}&id=${
                                    _that.data.infoId
                                }`,
                            });
                        }
                    },
                });
            }
        },
        getRequest(delflg) {
            let _that = this;
            let data = {
                authId: app.globalData.authId,
                id: _that.data.infoId,
                type: _that.data.type,
                delflg: delflg,
            };
            http.getRequest(`cjMap/doVerify`, data).then((res) => {
                if (res.status == 0) {
                    let pages = getCurrentPages(); //当前页面栈
                    let prevPage = pages[pages.length - 2]; //上一页面
                    if (_that.data.type == '05') {
                        prevPage.refreshCheckIn();
                    } else if (_that.data.type == '10') {
                        prevPage.refreshExperience();
                    } else {
                        prevPage.refreshInput();
                    }
                    wx.navigateBack({
                        delta: 1,
                    });
                }
            });
        },
    },
});
